﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace ProjectNocturnalFool
{
    class TextMessengerControl : UserControl
    {
        TextboxControl textbox;
        TextFieldControl textfield;

        /// <summary>
        /// Loads Content of button
        /// </summary>
        public override void LoadContent()
        {
            base.LoadContent();
            isDraggable = true;
            UserControl ctrlAdd;

            bgTexture = TacticsGame.Instance.Content.Load<Texture2D>("Menus/Buttons/Button");

            width = 100;
            height = 100;
            ctrlAdd = UILoader.addTextBox(0, 75);
            ctrlAdd.width = width;
            ctrlAdd.height =  height / 4;
            textbox = (TextboxControl)ctrlAdd;
            controls.Add(ctrlAdd);
            ctrlAdd = UILoader.addTextField(0, 0);
            ctrlAdd.width = width;
            ctrlAdd.height = height * 3 / 4;
            controls.Add(ctrlAdd);
            textfield = (TextFieldControl)ctrlAdd;
        }

        /// <summary>
        /// Updates logic based on mouse
        /// </summary>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (textbox.sendMessage)
            {
                textfield.addMessage(textbox.message);                
                textbox.message = "";
                textbox.sendMessage = false;
            }
            
        }
        public override void Draw(GameTime gameTime)
        {
            TacticsGame.Instance.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);

            Rectangle targetRect = new Rectangle(x, y, width, height);
            if (Selected)
            {
                TacticsGame.Instance.spriteBatch.Draw(bgTexture, targetRect, null, Color.Goldenrod, 0, Vector2.Zero, SpriteEffects.None, 0);
            }
            else
            {
                TacticsGame.Instance.spriteBatch.Draw(bgTexture, targetRect, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);
            }

            TacticsGame.Instance.spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
